<?
include('/var/www/html/new/d/module/api/glyld/glyld.class.php');
include('/var/www/html/new/d/module/api/function.class.php');

if (!class_exists("go_sql")){
	include("/var/www/html/new/conf/le.je");
	$le=new go_sql();
	$le->connect();
}
logfile(json_encode($_REQUEST));exit;
//{"pid":"18335","aid":"27491","begintime":"2015-08-19","flight_time":"D4F3888F0FDE41AB9A32315FD2F07279","tnum":"1","saveTo":"1","ordername":"\u5f6d\u5fd7\u840d","ordertel":"15959110796","memo":"","tourist_name_1":"\u5f6d\u5fd7\u840d","tourist_cert_1":"350321199108230123","paymode":"0"} paymode:0账户余额， 3产品自销，

if(!$_REQUEST['flight_time']) 
	exit("<script>alert('请选择航班');window.location.href='".$_SERVER['HTTP_REFERER']."';</script>"); 

$pid = $_REQUEST['pid'] + 0;
$select_uuid = "select uuid,id,landid from uu_jq_ticket where pid='$pid' limit 1";
$GLOBALS['le']->query($select_uuid);
if(!$GLOBALS['le']->fetch_assoc())
	exit('101');
$uuids = explode("_",$GLOBALS['le']->f('uuid'));  //查询票类id
$hline = $uuids[0]; //航线id
$ticketid = $uuids[1]; //票类id
$tid = $GLOBALS['le']->f('id');
$landid = $GLOBALS['le']->f('landid');

$sql="select dname,id from pft_member where account=".$_SESSION['account']." limit 1";
$GLOBALS['le']->query($sql);
$row1 = $GLOBALS['le']->fetch_assoc();
$dname =$row1['dname'];
$outSidePWD = $PFT_infunction->Create_Conn_REC($_SESSION['account'],$dname);

if($_REQUEST['paymode']==3)	$paystatus = 0 ; 
else 	$paystatus = $_REQUEST['paymode'] ;
$tuanhao = json_encode(array($tid,$_REQUEST['flight_time'],$_REQUEST['begintime']));
$submit_array = array(
	"account" => $_SESSION['account'],			//账号
	"password" => $outSidePWD,					//密码
	"lid" => $landid,							//景区id
	'tid'=>$tid,								//门票id
	'remoorder'=>'',							//远端订单号
	'tprice'=>100,								//以分为单位的单价
	'num' =>$_REQUEST['tnum'], 					//数量
	'playtime' => $_REQUEST['begintime'] ,  	//游玩日期
	'name'=> $_REQUEST['ordername'] ,			//客人姓名
	'tel'=>  $_REQUEST['ordertel'] ,			//客人手机号
	'sms'=> 1,									//短信
	'tuanhao'=>$tuanhao,						//团号
	'paystatus'=>$paystatus,
	'aid'=> $_REQUEST['aid'] , 					//供应商id
	'IDcard'=> $_REQUEST['tourist_cert_1'],  	//客人身份证
);
// print_r($submit_array);exit;
$outSide_submit =$PFT_infunction->outSide_Submit($submit_array);
$outSide_submit_xml = simplexml_load_string($outSide_submit);
if((string)$outSide_submit_xml->Rec->UUordernum){
	$url="http://www.12301.cc/orderSuc.html?ordernum=".(string)$outSide_submit_xml->Rec->UUordernum;
}else{
	$url="http://www.12301.cc/orderFailure.html?msg=".(string)$outSide_submit_xml->Rec->UUerrorcode;
}

// $endtime = microtime(true) - $starttime;
// logfile("sb1runtime: ".$endtime);

header("Location:$url"); 

function logfile($txt){
	$fp = fopen('/var/www/html/new/d/module/api/glyld/gly_logfile.txt',"a");
	flock($fp, LOCK_EX) ;
	fwrite($fp,$txt."\n");
	flock($fp, LOCK_UN);
	fclose($fp); 
}
?>